#include <stdlib.h>
#include <stdio.h>
#include "slave.h"
#include "3d7p_aceMesh.h"

__thread_local_fix int dest,src,i,j,k,s_iter,s_starti,s_endi,s_startj,s_endj,s_endk;

extern double A[2][SIZEX][SIZEY][SIZEZ];

#define alpha_d 0.0876
#define beta_d  0.0765


void stencil_core(targs* args)
{
    //printf("-\n");
    s_starti=args->starti;
    s_endi=args->endi;
    s_startj=args->startj;
    s_endj=args->endj;
    s_endk = args->k_N - 1;
    s_iter=args->iter;

    dest = s_iter  % 2 ;
    src = 1 - dest;
    for(i = s_starti; i < s_endi; i++)
      for(j = s_startj; j < s_endj; j++)
        for(k = 1; k < s_endk; k++) 
            A[dest][i][j][k] = alpha_d * (A[(src)][(i)][(j)][(k)]) + beta_d * (A[src][i-1][j][k] + A[src][i+1][j][k] + A[src][i][j-1][k] + A[src][i][j+1][k] + A[src][i][j][k-1] + A[src][i][j][k+1]);
}
